#include <iostream>
#include <fstream>
#include <stdexcept>
#include <cmath> 
#include <vector>
#include "Function.hpp"
#include "Interpolation.hpp"

class F1_B : public Function {
public:
    double operator() (double x) const {
        return 1/(1+x*x);
    }
};
double polynomial(double x, int n) {
    std::vector<double> vec;
    for(int i = 0; i<=n;i++){
            vec.push_back(-5 + 10*(double)i/n);
        }
    NewtonInterpolation newton(F1_B(),vec);
    return newton.interpolate(x);  
}
int main() {
    for (int n = 2; n <= 8; n=n+2) {
        std::ofstream file("data_B" + std::to_string(n) + ".csv");
        if (!file.is_open()) {
            std::cerr << "Failed to open file" << std::endl;
            return 1;
        }

        for (double x = -5; x <= 5; x += 0.1) {
            double y = polynomial(x, n);
            file << x << "," << y << std::endl;
        }

        file.close();
    }
    return 0; 
}

